import React, { Component } from 'react'
// withRouter 可以加工一个一般组件，让其具有路由的相关功能
import { withRouter } from "react-router-dom"

class Header extends Component {
    back = () => {
        this.props.history.goBack()
    }

    forward = () => {
        this.props.history.goForward()
    }

    goTwo = () => {
        this.props.history.go(2)
    }

    backTow = () => {
        this.props.history.go(-2)
    }
    render() {
        return (
            <div className="row">
                <div className="col-xs-offset-2 col-xs-8">
                    <div className="page-header">
                        <h2>React Router Demo</h2>
                        <button onClick={this.back}>返回</button>
                        <button onClick={this.forward}>前进</button>
                        <button onClick={this.goTwo}>前进两级</button>
                        <button onClick={this.backTow}>后退两级</button>
                    </div>

                </div>
            </div>
        )
    }
}
// 返回的是一个加工好的新组件
export default withRouter(Header)
